package com.wzb.hhunew.util;

import android.text.TextUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author wzb<wangzhibin_x@qq.com>
 * @date May 15, 2017 4:23:03 PM
 */
public class EncryptionUtil {

	/**
	 * MD5加密.
	 *
	 * @param msg
	 *            需要加密的文本.
	 * @return 加密文本.
	 */
	public static String md5Encrypt(String msg) {
		if (TextUtils.isEmpty(msg)) {
			return "";
		}
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(msg.getBytes());
			byte b[] = md.digest();
			int i;
			StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
			return buf.toString().toUpperCase();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			return "";
		}
	}

}
